﻿using System;
using System.Data;
using TuyennvLibrary.ServerApi.Models;
namespace ServerApi.administrator
{
    public partial class ListDevice : System.Web.UI.Page
    {
        TypeApplicationModel typeApplicationModel = new TypeApplicationModel();
        ApplicationModel appModel = new ApplicationModel();
        ApplicationDevicesModel appDeviceModel = new ApplicationDevicesModel();
        public int count = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadTypeApplication();
                LoadApplication();
                LoadTime();
            }
        }
        private void LoadTypeApplication()
        {
            DataTable dt = typeApplicationModel.GetListAll();
            ddlTypeApp.DataSource = dt;
            ddlTypeApp.DataTextField = "Name";
            ddlTypeApp.DataValueField = "Id";
            ddlTypeApp.DataBind();
        }
        private void LoadApplication()
        {
            DataTable dt = appModel.GetByField(TuyennvLibrary.ServerApi.Models.Application.COLUMN_TYPE_APP, int.Parse(ddlTypeApp.Text), TuyennvLibrary.ServerApi.Models.Application.COLUMN_NAME);
            ddlApplication.DataSource = dt;
            ddlApplication.DataTextField = "Name";
            ddlApplication.DataValueField = "appid";
            ddlApplication.DataBind();
        }
        private void LoadTime()
        {
            txtfromdate.Text = txttodate.Text = DateTime.Today.ToString("dd/MM/yyyy");
        }
        private void LoadData()
        {
            count = appDeviceModel.GetCountDevice(ddlApplication.Text, txtfromdate.Text, txttodate.Text);
        }
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            LoadData();
        }

        protected void ddlTypeShortCode_SelectedIndexChanged(object sender, EventArgs e)
        {
            LoadApplication();
        }
    }
}